#include "pictureimage.h"
#include <QDir>
#include <QDebug>

PictureImage::PictureImage():ImageBase()
{
    num =0;
}




int PictureImage::getCvMat(Mat &cvMat)
{

    if(!fileNameList.empty()){
         qDebug() << num ;
         fileFullName.clear();
         fileFullName= QString("%1/%2").arg(directoryName).arg(fileNameList.at((num++)%fileNameList.size()));
         qDebug() << fileFullName;
         cvMat = cv::imread(fileFullName.toStdString());
        return 0;
    }else{
        return -1;
    }
}

int PictureImage::setSource(QString path)
{
    QFileInfo fileinfo(path);
    if(fileinfo.isDir()){
        directoryName = path;
        fileNameList = getFileNames(path);
    }
}

QString PictureImage::getSource()
{
    return fileFullName;
}

QStringList PictureImage::getFileNames(const QString &path)
{
    QDir dir(path);
    QStringList nameFilters;
    nameFilters << "*.jpg" << "*.png";
    QStringList files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);

    return files;
}


